<?php

namespace Home\Model;

use Think\Model;

class SchoolModel extends Model {

    //实现学校信息的添加，如果成功返回1，失败则返回0
    public function addSchool($data) {              //实现学校信息添加                 
        $result = $this->add($data);   //把表单的数据添加到数据库
        return $result;
    }

    public function update($data) {         //实现学校信息修改功能
        var_dump($data);
        $schoolID = $data['ID'];
        $result = $this->where("ID=" . $schoolID)->save($data);
        return $result;
    }

    public function deleteSchool($id) {//school的主键在user表中为外键，会出现删除异常
        $result = $this->where('ID=' . $id)->delete();
        return $result;
    }

    public function queryAll() {
        // $sql="SELECT * FROM ".$this->tablePrefix."school";
        //$result=$this->query($sql);
        $result = $this->select();
        return $result;
    }
    public function queryById($id) {
        // $sql="SELECT * FROM ".$this->tablePrefix."school";
        //$result=$this->query($sql);
        $result = $this->field('schoolName')->where("ID=".$id)->select();
        return $result;
    }
    public function queryLikeByName($data) {//学校的id和学校名查询出来为空
        $schoolName='';
        for ($i = 0; $i < count($data); $i++) {//把数组中的单个查询字合成有%间隔的字符串
            $schoolName = $schoolName . $data[$i] . '%';
        }
        $result = $this->where("schoolName like '%" . $schoolName . "'")->select();
        return $result;
    }

}
